package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;

@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {

 //metaObject是原生参数
 @Override
 public void insertFill(MetaObject metaObject) {
  Date date=new Date();
  this.setFieldValByName("created", date,metaObject);
  this.setFieldValByName("updated", date,metaObject);
 }

 @Override
 public void updateFill(MetaObject metaObject) {
  this.setFieldValByName("updated",new Date(),metaObject);
 }
}
